package orbitPrototype.gui;

import orbitPrototype.event.EventHandler;
import orbitPrototype.objects.DisplayObjectContainer;

public class GUITabControl extends GUIElement
{
	private DisplayObjectContainer _tabs = null;

	private static final int BUTTON_WIDTH = 80;
	private static final int BUTTON_HEIGHT = 20;
	
	public static final int CONTENT_Y = BUTTON_HEIGHT;

	public GUITabControl(int x, int y, int width, int height, GUIWindow parentWindow)
	{
		super(x, y, width, height, parentWindow);
		
		_tabs = new DisplayObjectContainer(0, CONTENT_Y, width, height - CONTENT_Y);
		this.addChild(_tabs);
	}
	
	public void addTabs(GUITab[] tabs)
	{
		int buttonWidth = this.getWidth() / tabs.length;
		
		for(int i = 0; i < tabs.length; i++)
		{
			this.addChild(new GUIComplexButton(i * buttonWidth, 0, buttonWidth, BUTTON_HEIGHT, this.getParentWindow(), "openTab" + tabs[i].getTabTitle(), tabs[i], tabs[i].getTabTitle()));
			_tabs.addChild(tabs[i]);
			
			EventHandler.registerEventListener("openTab" + tabs[i].getTabTitle(), tabs[i], "activate", true);
		}
		
		activateTab(tabs[0]);
	}
	
	public void activateTab(GUITab tab)
	{
		_tabs.makeOnlyVisible(tab);
	}

}
